/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
*
*
* Authors:                                zhoujian
* Email:        343600434@qq.com
* Date:        Jan-09-2024 20:09:35
*
*/


#ifndef __device_H__
#define __device_H__


#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif
//ADC_CHANNEL_12
#define GUANGGAN_PORT GPIOA
#define GUANGGAN_PIN GPIO_PIN_0

//ADC_CHANNEL_13
#define PW_12V_IN_PORT GPIOC
#define PW_12V_IN_PIN GPIO_PIN_3

//ADC_CHANNEL_1
#define WENDU_PORT GPIOA
#define WENDU_PIN GPIO_PIN_1

//ADC_CHANNEL_2
#define YOULIANG_PORT GPIOA
#define YOULIANG_PIN GPIO_PIN_2

//#define SPI_USE_DMA
//#define LINURM_DEBUG_DIS_RATE_AND_SPEED

void guanggan_scan();
void adc_start();
void calibration_enable();
void adc_config(void);

void adc1_dma_init(uint32_t addr, uint32_t number);
void adc_data();

typedef struct {
    uint16_t trip;//单次里程
    uint16_t remain_mile;//剩余里程
    uint16_t odo;//总里程
    uint8_t mul;//里程倍率
    uint8_t speed;//车速
} RANGE_INFO;

extern RANGE_INFO range_info;
void rate_init();

extern uint16_t rate_v;
extern uint16_t pre_rate_v;


void trip_odo_handle();
void range_handle();
void display_range(int km_v);
void display_odo_trip(int km_v);

void trip_odo_show();

void adc_handle();
void oil_temprature_handle();
void temprature_handle();
void rate2speed();
void get_rate_value();
void get_speed_value();
void get_blue_status();
void boot_animation();
void reboot(void);
#ifdef SPI_USE_DMA

void LCD_RAM_DMA_W_color(uint16_t* color, uint8_t number);
void LCD_RAM_DMA_W_addr(uint16_t* addr, uint8_t number);
void LCD_RAM_DMA_W_addr_32(uint32_t* addr, uint8_t number);

#endif

#define XATL_APB 64000000

#define TIM1_PRESCAL1   64
#define TIM1_PRESCAL2   1

#define GPTIMClockFrequency (uint32_t)(XATL_APB/TIM1_PRESCAL1/TIM1_PRESCAL2)


#define     SPEED_HZ    1087
//(28261)

//#define LCD_PWM_BL

//#define LOG_PRINT
//#define DEBUG_TMP

#ifdef LOG_PRINT

#warning("LOG_PRINT !!!")
#define log_debug(...) printf(__VA_ARGS__)

#else

#define log_debug(...)

#endif

//#define ONLY_USE_RAISING_CAP_RATE
#ifdef DEBUG_TMP
#warning("DEBUG_TMP !!!")

void print_debug_tmp(void);
#endif

extern float f12v_in_ref;
extern float oil_ref;
extern float temperature_ref;
extern uint8_t is_lock_status;
//extern uint8_t speed_v;
typedef struct DEV_INFO {
    uint32_t guanggan;
} DEV_INFO_T;
extern DEV_INFO_T dev_t;

#define ADC_NUM 4
#define ADC_BUF_LEN 1

extern uint32_t adc_buf[ADC_NUM * ADC_BUF_LEN];

void bat_show(uint8_t v, uint8_t down);

uint8_t is_daoqi();

#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
class device
{

public:
    device();
    ~device();

};
#endif



#endif
